package com.xysd.examproject.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xysd.examproject.R;
import com.xysd.examproject.bean.AppInfo;

import java.util.List;

/**
 * Created by donghui on 2017/6/14.
 */

public class AppListAdapter extends BaseAdapter {
    private Context context;
    private List<AppInfo> dataList;

    public AppListAdapter(Context context, List<AppInfo> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public AppInfo getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_applist,null);
            holder=new ViewHolder();
            holder.appName= (TextView) convertView.findViewById(R.id.appName);
            holder.appPackage= (TextView) convertView.findViewById(R.id.appPackage);
            holder.appIcon= (ImageView) convertView.findViewById(R.id.appIcon);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        AppInfo info=dataList.get(position);
        holder.appName.setText(info.Appname);
        holder.appPackage.setText(info.packageName);
        holder.appIcon.setImageDrawable(info.appIcon);
        return convertView;
    }


    class ViewHolder{
        TextView appName,appPackage;
        ImageView appIcon;
    }
}
